package com.alm.token.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.alm.token.ConStant;
import com.alm.token.R;
import com.alm.token.base.BaseActivity;
import com.alm.token.ui.data.bean.AddDrawData;
import com.alm.token.ui.data.bean.DrawIndexData;
import com.alm.token.ui.data.bean.RegisterData;
import com.alm.token.ui.data.bean.TransferTransData;
import com.alm.token.ui.persenter.MyPreenter;
import com.alm.token.ui.view.TurmOutView;
import com.alm.token.utils.ActionBarHelper;
import com.alm.token.utils.EmptyUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import jnr.ffi.annotations.In;

import static com.alm.token.ui.activity.FundArealistActivity.INTENT_RESULT_CODE_VAULE;
import static com.alm.token.ui.activity.FundArealistActivity.INTENT_RESULT_SUCC_CODE;

//import com.uuzuche.lib_zxing.activity.CaptureActivity;
//import com.uuzuche.lib_zxing.activity.CodeUtils;
//import com.uuzuche.lib_zxing.activity.ZXingLibrary;

public class TurnOutBiTB_shoukuannumber_Activity extends BaseActivity implements TextWatcher, TurmOutView<Object> {

    @BindView(R.id.edt_inputmoney)
    EditText edtInputmoney;
    @BindView(R.id.tv_outmoneynext)
    TextView tvOutmoneynext;
    private String money = "";

    @Override
    protected MyPreenter initPreenter() {
        return new MyPreenter(this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_turnout_shoukuannumber;
    }

    @Override
    protected void initVariables() {
    }

    @Override
    protected void initViews() {
//        new ActionBarHelper(this).setTitle(getString(R.string.app_hint_superegg));
        new ActionBarHelper(this).setTitle(getString(R.string.tv_hint_setmoney));
        edtInputmoney.addTextChangedListener(this);
    }

    @Override
    protected void loadData() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.tv_outmoneynext:

                if (EmptyUtils.isNotEmpty(edtInputmoney.getText().toString())) {
                    money = edtInputmoney.getText().toString();
                    Intent intent = new Intent();
                    intent.putExtra(INTENT_RESULT_CODE_VAULE, money);
                    setResult(INTENT_RESULT_SUCC_CODE, intent);
                    finish();
                }

                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (s.toString().contains(".")) {
            if (s.length() - 1 - s.toString().indexOf(".") > 4) {
                s = s.toString().subSequence(0, s.toString().indexOf(".") + 5);
                edtInputmoney.setText(s);
                edtInputmoney.setSelection(s.length());
            }
        }
        if (s.toString().trim().substring(0).equals(".")) {
            s = "0" + s;
            edtInputmoney.setText(s);
            edtInputmoney.setSelection(2);
        }

        if (s.toString().startsWith("0")
                && s.toString().trim().length() > 1) {
            if (!s.toString().substring(1, 2).equals(".")) {
                edtInputmoney.setText(s.subSequence(0, 1));
                edtInputmoney.setSelection(1);
                return;
            }
        }

        if (EmptyUtils.isNotEmpty(s)) {
            tvOutmoneynext.setBackground(getResources().getDrawable(R.drawable.gradient_btn));
            tvOutmoneynext.setText(getString(R.string.tv_hint_next));
            tvOutmoneynext.setOnClickListener(this);
        } else {
            tvOutmoneynext.setBackground(getResources().getDrawable(R.drawable.gradient_btn_unclick));
            tvOutmoneynext.setText(getString(R.string.currency_hint1_warn));
            tvOutmoneynext.setOnClickListener(null);
        }
    }

    @Override
    public void afterTextChanged(Editable s) {
    }


    @Override
    public void getData(Object o) {

    }

    @Override
    public void jumpToLoginAct(int staue) {
        if (staue == 3) {
//            showToast(getString(R.string.common_relogin));
//            Intent intent = new Intent();
//            intent.setAction(ConStant.EXIT_APP);
//            sendBroadcast(intent);
//            startActivity(BlockWalletLoginActivity.class);
//            finish();
        } else if (staue == 4) {
//            showToast(getString(R.string.paypasw_hint_setpaypsw));
//            Intent intent = new Intent(this,PayPwdActivity.class);
//            intent.putExtra("PayPwdActivityType",PayPwdActivity.PAYPSW_SET);
//            startActivity(intent);
//            finish();
            showToSetPaypswDialog();
        } else if (staue == 666) {
            showToUpdata();
        }
    }

    @Override
    public void onError(String error) {
        showToast(error);
    }

    @Override
    public void ShowProgress() {
        showWaitDialog();
    }

    @Override
    public void hideProgress() {
        hideWaitDialog();
    }

    @Override
    public void getDrawIndexData(DrawIndexData drawIndexData) {

    }

    @Override
    public void getAddDrawData(AddDrawData addDrawData) {

    }

    @Override
    public void getCode(RegisterData registerData) {

    }

    @Override
    public void getTransferIndexData(DrawIndexData drawIndexData) {

    }

    @Override
    public void getTransfertransData(TransferTransData transferTransData) {

    }

    @Override
    public void getcheckLoginNameData(RegisterData checkLoginNameData) {

    }
}
